package com.knight.hadoop.day05.simulate.hdf;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class DataNodeServer {

	private static final String fileName = "1.exe";

	public static void receiveFile() throws IOException {
		ServerSocket serverSocket = new ServerSocket(10000);
		System.out.println("dataNode已启动");
		
		while (true) {
			Socket socket = serverSocket.accept();

			InputStream in = socket.getInputStream();

			FileUtils.upload(in, fileName);
			socket.close();
		}
	}
	
	public static void sendFile() throws IOException{
		ServerSocket serverSocket = new ServerSocket(10000);
		System.out.println("dataNode已启动");
		
		while (true) {
			Socket socket = serverSocket.accept();

			FileUtils.downloadSocket(socket, fileName);
			socket.close();
		}
	}

	public static void main(String[] args) throws IOException {
		sendFile();
	}

}
